<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of FamilyDAO
 *
 * @author gaurav
 */
require_once('FirePHPCore/FirePHP.class.php');
require_once('FirePHPCore/fb.php');
include_once 'interface/family.php';
include_once 'utility/DataBaseUtility.php';
include_once 'config/Constant.php';
include_once 'DTO/FamilyDTO.php';

class FamilyDAO {

    public function getFamily(){

             // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        $sql = "SELECT ". Constant::$FAMILY_COL_FAMILY_ID . "," .Constant::$FAMILY_COL_FAMILY_NAME ." , ".Constant::$FAMILY_COL_FAMILY_COUNTRY_ID." ,". Constant::$FAMILY_COL_FAMILY_STATE_ID . ", ". Constant::$FAMILY_COL_FAMILY_CITY_ID. " , ". Constant::$FAMILY_COL_FAMILY_ADDRESS . " , ". Constant::$FAMILY_COL_FAMILY_GOTRA_ID." FROM ".Constant::$TABLE_FAMILY;

        $result = mysql_query($sql);
        $allFamilyArray[] = Array();
        while($row = mysql_fetch_assoc($result)) {
            $tempFamily = new FamilyDTO();
           $tempFamily->setId($row[Constant::$FAMILY_COL_FAMILY_ID]);
           $tempFamily->setFamilyName($row[Constant::$FAMILY_COL_FAMILY_NAME]);
           $tempFamily->setCountryId($row[Constant::$FAMILY_COL_FAMILY_COUNTRY_ID]);
           $tempFamily->setStateId($row[Constant::$FAMILY_COL_FAMILY_STATE_ID]);
           $tempFamily->setCityId($row[Constant::$FAMILY_COL_FAMILY_CITY_ID]);
           $tempFamily->setAddress($row[Constant::$FAMILY_COL_FAMILY_ADDRESS]);
           $tempFamily->setGotraId($row[Constant::$FAMILY_COL_FAMILY_GOTRA_ID]);

            
            $allFamilyArray[] = $tempFamily;
            if(Constant::$APPICATION_MODE == "D") {
                FB::info("SQL --".$sql);
                FB::info("id: ". $row[Constant::$FAMILY_COL_FAMILY_ID]. " Family Name : ". $row[Constant::$FAMILY_COL_FAMILY_NAME]. " Country Id :". $row[Constant::$FAMILY_COL_FAMILY_COUNTRY_ID]." FAMILY_STATE_ID : ". $row[Constant::$FAMILY_COL_FAMILY_STATE_ID]." FAMILY_CITY_ID : ". $row[Constant::$FAMILY_COL_FAMILY_CITY_ID]. " FAMILY_ADDRESS : ". $row[Constant::$FAMILY_COL_FAMILY_ADDRESS]." FAMILY_GOTRA_ID : ". $row[Constant::$FAMILY_COL_FAMILY_GOTRA_ID] );
            }

          
        }
        return $allFamilyArray;

    } // to get all family

	public function getFamilyById($familyId){

               // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        $sql = "SELECT ". Constant::$FAMILY_COL_FAMILY_ID . "," .Constant::$FAMILY_COL_FAMILY_NAME ." , ".Constant::$FAMILY_COL_FAMILY_COUNTRY_ID." ,". Constant::$FAMILY_COL_FAMILY_STATE_ID . ", ". Constant::$FAMILY_COL_FAMILY_CITY_ID. " , ". Constant::$FAMILY_COL_FAMILY_ADDRESS . " , ". Constant::$FAMILY_COL_FAMILY_GOTRA_ID." FROM ".Constant::$TABLE_FAMILY. " where ". Constant::$FAMILY_COL_FAMILY_ID. " = ". $familyId;

        $result = mysql_query($sql);
        $allFamilyArray[] = Array();
        while($row = mysql_fetch_assoc($result)) {
            $tempFamily = new FamilyDTO();
           $tempFamily->setId($row[Constant::$FAMILY_COL_FAMILY_ID]);
           $tempFamily->setFamilyName($row[Constant::$FAMILY_COL_FAMILY_NAME]);
           $tempFamily->setCountryId($row[Constant::$FAMILY_COL_FAMILY_COUNTRY_ID]);
           $tempFamily->setStateId($row[Constant::$FAMILY_COL_FAMILY_STATE_ID]);
           $tempFamily->setCityId($row[Constant::$FAMILY_COL_FAMILY_CITY_ID]);
           $tempFamily->setAddress($row[Constant::$FAMILY_COL_FAMILY_ADDRESS]);
           $tempFamily->setGotraId($row[Constant::$FAMILY_COL_FAMILY_GOTRA_ID]);


            $allFamilyArray[] = $tempFamily;
            if(Constant::$APPICATION_MODE == "D") {
                FB::info("SQL --".$sql);
                FB::info("id: ". $row[Constant::$FAMILY_COL_FAMILY_ID]. " Family Name : ". $row[Constant::$FAMILY_COL_FAMILY_NAME]. " Country Id :". $row[Constant::$FAMILY_COL_FAMILY_COUNTRY_ID]." FAMILY_STATE_ID : ". $row[Constant::$FAMILY_COL_FAMILY_STATE_ID]." FAMILY_CITY_ID : ". $row[Constant::$FAMILY_COL_FAMILY_CITY_ID]. " FAMILY_ADDRESS : ". $row[Constant::$FAMILY_COL_FAMILY_ADDRESS]." FAMILY_GOTRA_ID : ". $row[Constant::$FAMILY_COL_FAMILY_GOTRA_ID] );
            }


        }
        return $allFamilyArray;
        } // to get Family By Id
	public function getFamilyByFamilyName($familyName){


                  // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();
        $sql = "SELECT ". Constant::$FAMILY_COL_FAMILY_ID . "," .Constant::$FAMILY_COL_FAMILY_NAME ." , ".Constant::$FAMILY_COL_FAMILY_COUNTRY_ID." ,". Constant::$FAMILY_COL_FAMILY_STATE_ID . ", ". Constant::$FAMILY_COL_FAMILY_CITY_ID. " , ". Constant::$FAMILY_COL_FAMILY_ADDRESS . " , ". Constant::$FAMILY_COL_FAMILY_GOTRA_ID." FROM ".Constant::$TABLE_FAMILY. " where ". Constant::$FAMILY_COL_FAMILY_NAME. " = '". $familyName ."'";
         
        $result = mysql_query($sql);
        $allFamilyArray[] = Array();
        while($row = mysql_fetch_assoc($result)) {
            $tempFamily = new FamilyDTO();
           $tempFamily->setId($row[Constant::$FAMILY_COL_FAMILY_ID]);
           $tempFamily->setFamilyName($row[Constant::$FAMILY_COL_FAMILY_NAME]);
           $tempFamily->setCountryId($row[Constant::$FAMILY_COL_FAMILY_COUNTRY_ID]);
           $tempFamily->setStateId($row[Constant::$FAMILY_COL_FAMILY_STATE_ID]);
           $tempFamily->setCityId($row[Constant::$FAMILY_COL_FAMILY_CITY_ID]);
           $tempFamily->setAddress($row[Constant::$FAMILY_COL_FAMILY_ADDRESS]);
           $tempFamily->setGotraId($row[Constant::$FAMILY_COL_FAMILY_GOTRA_ID]);


            $allFamilyArray[] = $tempFamily;
            if(Constant::$APPICATION_MODE == "D") {
                FB::info("SQL --".$sql);
                FB::info("id: ". $row[Constant::$FAMILY_COL_FAMILY_ID]. " Family Name : ". $row[Constant::$FAMILY_COL_FAMILY_NAME]. " Country Id :". $row[Constant::$FAMILY_COL_FAMILY_COUNTRY_ID]." FAMILY_STATE_ID : ". $row[Constant::$FAMILY_COL_FAMILY_STATE_ID]." FAMILY_CITY_ID : ". $row[Constant::$FAMILY_COL_FAMILY_CITY_ID]. " FAMILY_ADDRESS : ". $row[Constant::$FAMILY_COL_FAMILY_ADDRESS]." FAMILY_GOTRA_ID : ". $row[Constant::$FAMILY_COL_FAMILY_GOTRA_ID] );
            }


        }
        return $allFamilyArray;
        }
	public function setFamily( $familyName, $countryId, $stateId, $cityId, $address, $gotraId){

              // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "INSERT INTO ".Constant::$TABLE_FAMILY." (".Constant::$FAMILY_COL_FAMILY_NAME. ", ". Constant::$FAMILY_COL_FAMILY_COUNTRY_ID . ", ". Constant::$FAMILY_COL_FAMILY_STATE_ID.", ". Constant::$FAMILY_COL_FAMILY_CITY_ID. ", ". Constant::$FAMILY_COL_FAMILY_ADDRESS. ",". Constant::$FAMILY_COL_FAMILY_GOTRA_ID .") VALUES ( '".$familyName."' ,'".$countryId."' , '". $stateId ."' , '" .$cityId. "' , '". $address ."' , '" .$gotraId. "')";

        $result = mysql_query($sql);
        if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }

        mysql_close($connection);

        } // to insert the  Family
        
	public function setFamilyById($familyId, $familyName, $countryId, $stateId, $cityId, $address, $gotraId ){

            // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "UPDATE ".Constant::$TABLE_FAMILY." SET ".Constant::$FAMILY_COL_FAMILY_NAME." = '".$familyName."', ".Constant::$FAMILY_COL_FAMILY_COUNTRY_ID. " = '".$countryId. "', ". Constant::$FAMILY_COL_FAMILY_STATE_ID. " = '". $stateId ."', ". Constant::$FAMILY_COL_FAMILY_CITY_ID. " = '". $cityId ."' , ". Constant::$FAMILY_COL_FAMILY_ADDRESS ." = '". $address . "' , ". Constant::$FAMILY_COL_FAMILY_GOTRA_ID. " = '". $gotraId ."'  WHERE ".Constant::$FAMILY_COL_FAMILY_ID." = '".$familyId."'";
         FB::info("SQL --".$sql);
        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);

        } // to update the family by id
	public function removeFamily(){

          // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "DELETE FROM ".Constant::$TABLE_FAMILY."";

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);
        } // to delete all the family
	public function removeFamilyById($familyId){

          // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "DELETE FROM ".Constant::$TABLE_FAMILY." where ". Constant::$FAMILY_COL_FAMILY_ID ." = ".$familyId."";

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);

        } // to delete the family by id
	public function removeFamilyByFamilyName($familyName){

             // to start logging on firebug tool
        ob_start();

        $connection =  DataBaseUtility::getConection();

        $sql = "DELETE FROM ".Constant::$TABLE_FAMILY." where ". Constant::$FAMILY_COL_FAMILY_NAME ." = '".$familyName."'";

        $result = mysql_query($sql);
         if(Constant::$APPICATION_MODE == "D") {
            FB::info("SQL --".$sql);

        }
        mysql_close($connection);
        } // to delete the family by family Name
}
?>
